/***************************************************************
 *  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
 *  All rights reserved.
 *
 *  This file is part of the GroupMe! Project. Source code of 
 *  this project is closed and redistribution of this code is
 *  prohibited. 
 *  
 *  Contact: http://www.groupme.net
 *
 *  This copyright notice MUST APPEAR in all copies of the file!
 ***************************************************************/
package net.groupme.similarityComputer;

import java.net.URL;

import junit.framework.TestCase;

import net.groupme.exceptions.InsertFailedException;
import net.groupme.model.Tag;
import net.groupme.model.UserImpl;
import net.groupme.model.dao.UserDAOTest;
import net.groupme.model.dao.mem.GroupDAOMemImpl;
import net.groupme.model.dao.mem.ResourceDAOMemImpl;
import net.groupme.model.dao.mem.TagDAOMemImpl;

import org.junit.Before;
import org.junit.Test;

import com.aetrion.flickr.people.User;

public class SimComTest extends TestCase {

	private GroupDAOMemImpl group1 = null;
	private GroupDAOMemImpl group2 = null;
	private ResourceDAOMemImpl resource1 = null;
	private ResourceDAOMemImpl resource2 = null;
	private TagDAOMemImpl tag1 = null;
	private TagDAOMemImpl tag2 = null;
	@Before
	public void setUp() throws Exception {
		group1 = new GroupDAOMemImpl("0001", "Gruppe1", "TestGruppe1");
		group2 = new GroupDAOMemImpl("0002", "Gruppe2", "TestGruppe2");
		URL url1 = new URL("http://www.groupme.org");
		resource1 = new ResourceDAOMemImpl("0003", "Resource1",
				"TestResource1", url1, "website");
		URL url2 = new URL("http://www.test.org");
		resource1 = new ResourceDAOMemImpl("0003", "Resource1",
				"TestResource1", url1, "website");
		resource2 = new ResourceDAOMemImpl("0004", "Resource2",
				"TestResource2", url2, "website");
		tag1 = new TagDAOMemImpl("0005", "TestTag", "TestTag");
		tag2 = new TagDAOMemImpl("0006", "TestTag2", "TestTag2");
	

	}

	@Test
	public void testComputeScoreForTags() throws Exception {
		SimCom simCom = new SimCom(group1, group2);

		assertEquals(0, simCom.getScoreForTags());

		
		group1.addResource(resource1);
		group2.addResource(resource1);
		
		resource1.addTag(null, tag1);
		resource1.addTag(null, tag1);

		assertEquals(100, simCom.getScoreForTags());

		group1.addTag(null, tag1);

		assertEquals(100, simCom.getScoreForTags());
		
		group2.addTag(null, tag2);
		
		assertEquals(100, simCom.getScoreForTags());
		
	    group1.addTag(null, tag2);
		
		assertEquals(110, simCom.getScoreForTags());
	}

	@Test
	public void testComputeScoreForReources() throws Exception {
		SimCom simCom = new SimCom(group1, group2);

		assertEquals(0, simCom.getScoreForResources());
		
		group1.addResource(resource1);
		group2.addResource(resource1);
		
		assertEquals(1000, simCom.getScoreForResources());
		
		group2.removeResource(resource1);
		
		assertEquals(0, simCom.getScoreForResources());
		
		group2.addResource(resource2);

		assertEquals(0, simCom.getScoreForResources());
		
		group2.addResource(resource1);
		
		assertEquals(1000, simCom.getScoreForResources());
	
		group1.addResource(resource2);
		assertEquals(2000, simCom.getScoreForResources());
}
}
